package com.macro.mall.controller;

import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.ReportTotalEntDTO;
import com.macro.mall.dto.o.ReportTotalOutDTO;
import com.macro.mall.service.ReportTotalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/report/total")
public class ReportTotalController {
    @Autowired
    private ReportTotalService reportTotalService;

    @RequestMapping("/list")
    public CommonResult list(@RequestBody ReportTotalEntDTO reportTotalEntDTO){
        PageInfo<ReportTotalOutDTO> list = reportTotalService.list(reportTotalEntDTO);
        return CommonResult.success(list);
    }

    @RequestMapping("/modify")
    public CommonResult modify(@RequestBody ReportTotalEntDTO reportTotalEntDTO){
        int modify = reportTotalService.modify(reportTotalEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setStatus")
    public CommonResult setStatus(@RequestBody ReportTotalEntDTO reportTotalEntDTO){
        int modify = reportTotalService.modify(reportTotalEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

}
